#include <REGX52.H>
#include "Delay.h"
#include "Nixie.h"


typedef unsigned char u8;

//共阴极数码管字形码编码
u8 code NixieTable[] = {0x3f,0x06,0x5b,0x4f,0x66, //0 1 2 3 4
					 0x6d,0x7d,0x07,0x7f,0x6f, //5 6 7 8 9
					 0x77,0x7c,0x58,0x5e,0x79, //A b c d E
					 0x71,0x76,0x30,0x0e,0x38, //F H I J L
					 0x54,0x5c,0x73,0x67,0x50, //n o p q r
					 0x6d,0x3e,0x1c,0x6e};     //s U v y  



void Nixie(unsigned char Location, unsigned char Number)
{
	switch(Location)
	{
		case 8: P2_4 = 1; P2_3 = 1; P2_2 = 1; break;
		case 7: P2_4 = 1; P2_3 = 1; P2_2 = 0; break;
		case 6: P2_4 = 1; P2_3 = 0; P2_2 = 1; break;
		case 5: P2_4 = 1; P2_3 = 0; P2_2 = 0; break;
		case 4: P2_4 = 0; P2_3 = 1; P2_2 = 1; break;
		case 3: P2_4 = 0; P2_3 = 1; P2_2 = 0; break;
		case 2: P2_4 = 0; P2_3 = 0; P2_2 = 1; break;
		case 1: P2_4 = 0; P2_3 = 0; P2_2 = 0; break;
	}
	
	if(Number <= 9)
		P0 = NixieTable[Number];
	

	//数码管消影
	//Delay(1);	//延时1ms让数码管显示，延时过短数字显示亮度较暗
	//P0 = 0;		//共阴极数码管，段码清零
}


void NixieShowNum(unsigned int Number)
{
	unsigned int localtion = 1;
	unsigned int value = 0;
	
	while(Number)
	{
		value = Number % 10;
		Number = Number / 10;
		Nixie(localtion, value);
		
		localtion++;
	}
}
